# Copyright (C) 2023 - 2025 Advanced Micro Devices, Inc.  All rights reserved.
# Copyright (c) 2021 Xilinx, Inc.  All rights reserved.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.15)
project(intc)

find_package(common)
set(INTC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(INTC QUIET)
set(defs "")
list(APPEND defs "#ifndef XINTC_DRV_CONFIG_H_\n")
list(APPEND defs "#define XINTC_DRV_CONFIG_H_\n\n")
if ((EXISTS "${INTC_DIR}/INTCConfig.cmake") AND
    DRIVER_INSTANCES)
	set(max_intr 0)

	foreach(ELEMENT ${TOTAL_DRIVER_PROP_LIST})
		foreach(ENTRY ${ELEMENT})
			list(GET ${ENTRY} 5 max_intr_temp)
		if(max_intr_temp GREATER max_intr)
				set(max_intr ${max_intr_temp})
			endif()
		endforeach()
	endforeach()
    list(LENGTH DRIVER_INSTANCES drv_instances)
    list(APPEND defs "#define XPAR_INTC_MAX_NUM_INTR_INPUTS ${max_intr}\n")
    list(APPEND defs "#define XPAR_INTC_NUM_DRV_INSTANCES ${drv_instances}\n")
endif()
list(APPEND defs "\n#endif")
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/xintc_drv_config.h ${defs})
collector_create (PROJECT_LIB_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}")
collector_create (PROJECT_LIB_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}")
include_directories(${CMAKE_BINARY_DIR}/include)
collect (PROJECT_LIB_SOURCES xintc.c)
collect (PROJECT_LIB_HEADERS xintc.h)
collect (PROJECT_LIB_HEADERS xintc_drv_config.h)
collect (PROJECT_LIB_SOURCES xintc_g.c)
collect (PROJECT_LIB_HEADERS xintc_i.h)
collect (PROJECT_LIB_SOURCES xintc_intr.c)
collect (PROJECT_LIB_SOURCES xintc_l.c)
collect (PROJECT_LIB_HEADERS xintc_l.h)
collect (PROJECT_LIB_SOURCES xintc_options.c)
collect (PROJECT_LIB_SOURCES xintc_selftest.c)
collector_list (_sources PROJECT_LIB_SOURCES)
collector_list (_headers PROJECT_LIB_HEADERS)
file(COPY ${_headers} DESTINATION ${CMAKE_BINARY_DIR}/include)
add_library(intc STATIC ${_sources})
set_target_properties(intc PROPERTIES LINKER_LANGUAGE C)
